package com.yet.kotlinapp.net

import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.adapter.rxjava3.RxJava3CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

/**
 *
 * @ProjectName: Kotlin app
 * @Package: com.yet.kotlinapp.api
 * @ClassName: ApiClient
 * @Description: java类作用描述
 * @Author: liys
 * @CreateDate: 2021/8/25 16:08
 * @UpdateUser: 更新者
 * @UpdateDate: 2021/8/25 16:08
 * @UpdateRemark: 更新说明
 * @Version: 1.0
 */
class ApiClient {

    private object Holder{
        var INSTANCE=ApiClient();
    }

    companion object{
        var instance=Holder.INSTANCE;
    }

    fun  <T> instanceRetrofit(apiinstance:Class<T>) :T {

        var mokhttp=OkHttpClient()
            .newBuilder()
            .readTimeout(2000,TimeUnit.SECONDS)
            .connectTimeout(2000,TimeUnit.SECONDS)
            .writeTimeout(2000,TimeUnit.SECONDS)
            .build()

        var retrofit:Retrofit = Retrofit.Builder()
            .client(mokhttp)
            .baseUrl("https://www.wanandroid.com")
            .addCallAdapterFactory(RxJava3CallAdapterFactory.create())
            .addConverterFactory(GsonConverterFactory.create())
            .build()
        return retrofit.create(apiinstance);
    }


}